package format

import (
	"encoding/json"
	"fmt"
	"os"
)

func FormatToJson(i any) string {
	res, _ := json.MarshalIndent(i, "", "   ")
	return string(res)
}

func FormatBytesToJsion(d []byte) string {
	var data interface{}
	err := json.Unmarshal(d, &data)
	if err != nil {
		fmt.Println("error unmarshalling json:", err)
		os.Exit(1)
	}
	res, _ := json.MarshalIndent(data, "", "   ")
	return string(res)
}

func IndexOf(lst []string, one string) int {
	for i, p := range lst {
		if p == one {
			return i
		}
	}
	return -1
}
